<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8" />
    <title>机器人设置</title>
    <link
      rel="stylesheet"
      href="/app/admin/component/layui/css/layui.css?v=2.8.12"
    />
    <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
    <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
  </head>
  <body>
    <form class="layui-form" action="" onsubmit="return false">
      <div class="mainBox">
        <div class="layui-card">
          <div class="layui-card-body">
            <div class="layui-tab layui-tab-brief">
              <ul class="layui-tab-title">
                <li class="layui-this">文件设置</li>
                <!-- <li>命令设置</li> -->
              </ul>
              <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                  <table
                    class="layui-hide"
                    id="file_settings"
                    lay-filter="file_settings"
                  ></table>
                </div>
                <div class="layui-tab-item">
                  <table
                    class="layui-hide"
                    id="commands_settings"
                    lay-filter="commands_settings"
                  ></table>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="bottom" style="bottom: 0">
        <div class="button-container">
          <button
            type="submit"
            class="pear-btn pear-btn-primary pear-btn-md"
            lay-submit=""
            lay-filter="save"
          >
            提交
          </button>
          <button type="reset" class="pear-btn pear-btn-md">重置</button>
        </div>
      </div>
    </form>
  </body>
  <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
  <script src="/app/admin/component/pear/pear.js"></script>
  <script src="/app/admin/admin/js/permission.js"></script>
  <script>
    layui.use(["form",'jquery',"popup"],function(){
      var table = layui.table, $ = layui.$, form = layui.form,layer = layui.layer;
      table.render({
        elem: '#file_settings',
        data: <?=json_encode($file_types)?>,
        cols:[
          [
            {
              field:'title',
              title:'类型',
            },
            {
              field:'perfix',
              title:'前缀',
              templet:'<div><input type="text" name="type[{{= d.type}}]" placeholder=""前缀 autocomplete="off" class="layui-input" value="{{= d.perfix }}"> </div>'
            },
          ],
        ],
        cellMinWidth: 40,
        skin: "line",
        size: "lg",
        page: false,
      })

      form.on("submit(save)", function (data) {
        var loading = layer.msg('提交中,请勿刷新页面', {
          icon: 16,
          shade: 0.3,
          time: 0,
        });
        $.ajax({
          method:'POST',
          data: data.field,
          success: function(data){
            if(data.code == 0){
              return layui.popup.success("操作成功", function () {
                parent.refreshTable();
                parent.layer.close(parent.layer.getFrameIndex(window.name));
              });
            }else{
              return layui.popup.failure(data.msg || '操作失败');
            }
          },
          complete: function(){
            layer.close(loading);
          },
          error:function(){
            return layui.popup.failure('操作失败,请重试');
          }
        })
        return false;
      });
    });
  </script>
</html>
